package com.ypd.shop.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ypd.common.core.domain.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ypd.common.annotation.Log;
import com.ypd.common.core.controller.BaseController;
import com.ypd.common.core.domain.AjaxResult;
import com.ypd.common.enums.BusinessType;
import com.ypd.shop.domain.Properties;
import com.ypd.shop.service.IPropertiesService;
import com.ypd.common.utils.poi.ExcelUtil;
import com.ypd.common.core.page.TableDataInfo;

/**
 * 店铺管理Controller
 * 
 * @author lin
 * @date 2025-02-28
 */

@RestController
@RequestMapping("/shop/properties")
@Api(tags = "店铺管理Controller")
public class PropertiesController extends BaseController
{
    @Autowired
    private IPropertiesService propertiesService;

    /**
     * 查询店铺管理列表
     */
    @ApiOperation("查询店铺管理列表")
//    @PreAuthorize("@ss.hasPermi('shop:properties:list')")
    @GetMapping("/list")
    public TableDataInfo list(Properties properties)
    {
        startPage();
        List<Properties> list = propertiesService.selectPropertiesList(properties);
        return getDataTable(list);
    }
    /**
     * 查询我的店铺管理列表
     */
    @ApiOperation("查询我的店铺管理列表")
    @GetMapping("/myList")
    public TableDataInfo myList(Properties properties)
    {
        startPage();
        List<Properties> list = propertiesService.selectPropertiesMyList(properties);
        return getDataTable(list);
    }

    /**
     * 用户端查询店铺列表
     */
    @ApiOperation("查询店铺管理列表")
//    @PreAuthorize("@ss.hasPermi('shop:properties:listUser')")
    @GetMapping("/listUser")
    public TableDataInfo listUser(Properties properties)
    {
        startPage();
        List<Properties> list = propertiesService.selectPropertiesListByUser(properties);
        return getDataTable(list);
    }


    /**
     * 导出店铺管理列表
     */
    @ApiOperation("导出店铺管理列表")
//    @PreAuthorize("@ss.hasPermi('shop:properties:export')")
    @Log(title = "店铺管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Properties properties)
    {
        List<Properties> list = propertiesService.selectPropertiesList(properties);
        ExcelUtil<Properties> util = new ExcelUtil<Properties>(Properties.class);
        util.exportExcel(response, list, "店铺管理数据");
    }

    /**
     * 获取店铺管理详细信息
     */
    @ApiOperation("获取店铺管理详细信息")
//    @PreAuthorize("@ss.hasPermi('shop:properties:query')")
    @GetMapping(value = "/{propertyId}")
    public AjaxResult getInfo(@PathVariable("propertyId") Long propertyId)
    {
        return success(propertiesService.selectPropertiesByPropertyId(propertyId));
    }

    /**
     * 新增店铺管理
     */
    @ApiOperation("新增店铺管理")
//    @PreAuthorize("@ss.hasPermi('shop:properties:add')")
    @Log(title = "店铺管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Properties properties)
    {
        return toAjax(propertiesService.insertProperties(properties));
    }

    /**
     * 修改店铺管理
     */
    @ApiOperation("修改店铺管理")
//    @PreAuthorize("@ss.hasPermi('shop:properties:edit')")
    @Log(title = "店铺管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Properties properties)
    {
        return toAjax(propertiesService.updateProperties(properties));
    }

    /**
     * 删除店铺管理
     */
    @ApiOperation("删除店铺管理")
//    @PreAuthorize("@ss.hasPermi('shop:properties:remove')")
    @Log(title = "店铺管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{propertyIds}")
    public AjaxResult remove(@PathVariable Long[] propertyIds)
    {
        return toAjax(propertiesService.deletePropertiesByPropertyIds(propertyIds));
    }
}
